get-data.RmdSuppose you wish to tabulate ACS one-year 2019 data for estimates of total people by race and ethnicity, as provided in table B03002 by PSRC counties. You would use the following function call:
get_acs_recs(geography = 'county',
table.names = 'B03002',
years = 2019,
acs.type = 'acs1')## # A tibble: 105 x 11
## GEOID name state variable estimate moe label concept census_geography
## <chr> <chr> <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
## 1 53033 King ~ Wash~ B03002_~ 2252782 NA Estimat~ HISPANI~ County
## 2 53033 King ~ Wash~ B03002_~ 2030140 NA Estimat~ HISPANI~ County
## 3 53033 King ~ Wash~ B03002_~ 1302544 3208 Estimat~ HISPANI~ County
## 4 53033 King ~ Wash~ B03002_~ 147822 4678 Estimat~ HISPANI~ County
## 5 53033 King ~ Wash~ B03002_~ 13321 1990 Estimat~ HISPANI~ County
## 6 53033 King ~ Wash~ B03002_~ 424590 7085 Estimat~ HISPANI~ County
## 7 53033 King ~ Wash~ B03002_~ 15702 1831 Estimat~ HISPANI~ County
## 8 53033 King ~ Wash~ B03002_~ 6574 3281 Estimat~ HISPANI~ County
## 9 53033 King ~ Wash~ B03002_~ 119587 8804 Estimat~ HISPANI~ County
## 10 53033 King ~ Wash~ B03002_~ 2639 1744 Estimat~ HISPANI~ County
## # ... with 95 more rows, and 2 more variables: acs_type <chr>, year <dbl>
By default, without specifying any counties, the jurisdictions returned will be King, Kitsap, Pierce, and Snohomish Counties. Use ?get_acs_recs() for other default values implemented in this function.
To retrieve non-PSRC counties or a subset of the default counties, use the counties argument and provide a vector of counties (e.g. counties = c("King", "Thurston")). Do not use the fips argument as that is reserved for MSA or place geographies.
The get_decennial_recs() to generate Decennial Census tables operates similarly to the get_acs_recs(). If you wanted to retrieve housing units and total population by MSA, you would call the following:
get_decennial_recs(geography = 'msa',
table_codes = c("H001", "P001"),
years = c(2010),
fips = c('42660', "28420"))## # A tibble: 4 x 6
## GEOID NAME variable value label concept
## <chr> <chr> <chr> <dbl> <chr> <chr>
## 1 28420 Kennewick-Pasco-Richland, WA Metro Area H001001 93041 Total HOUSING ~
## 2 42660 Seattle-Tacoma-Bellevue, WA Metro Area H001001 1463295 Total HOUSING ~
## 3 28420 Kennewick-Pasco-Richland, WA Metro Area P001001 253340 Total TOTAL PO~
## 4 42660 Seattle-Tacoma-Bellevue, WA Metro Area P001001 3439809 Total TOTAL PO~
Note: the table names are padded with 0s, so you call “H001” as opposed to “H1” as you would in Elmer. Only SF1 tables are currently implemented.
Let’s say you want to create a map of the tracts in the region for one variable. You can use the function create_tract_map(). Here’s an example, mapping non-Hispanic Black or African American population alone by tract:
## Warning: package 'sf' was built under R version 4.0.5
## Warning: package 'dplyr' was built under R version 4.0.5
tract.big.tbl <- get_acs_recs(geography ='tract',
table.names = 'B03002',
years = 2019)
tract.tbl <- tract.big.tbl %>%
filter(label=='Estimate!!Total:!!Not Hispanic or Latino:!!Black or African American alone')
tract.url <- "https://services6.arcgis.com/GWxg6t7KXELn1thE/arcgis/rest/services/tract2010_nowater/FeatureServer/0/query?where=0=0&outFields=*&f=pgeojson"
#'
tract.lyr<-st_read(tract.url)## Reading layer `OGRGeoJSON' from data source
## `https://services6.arcgis.com/GWxg6t7KXELn1thE/arcgis/rest/services/tract2010_nowater/FeatureServer/0/query?where=0=0&outFields=*&f=pgeojson'
## using driver `GeoJSON'
## Simple feature collection with 773 features and 21 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -123.0234 ymin: 46.72799 xmax: -120.9062 ymax: 48.29924
## Geodetic CRS: WGS 84
create_tract_map(tract.tbl,
tract.lyr,
map.title='Black, non-Hispanic Population',
map.title.position='topleft',
legend.title='Black, Non-Hispanic Population',
legend.subtitle='by Census Tract')